"""
Case Type   : 进程
Case Name   : 无full参数-查看字段数量及拼写是否正确
Create At   : 2024.8.19
Owner       : wang-tianjing1
Description :
    1、设置dolphin.b_compatibility_mode参数为on
    2、使用?相关操作符
    3、恢复dolphin.b_compatibility_mode参数
Expect      :
    1、成功
    2、失败，合理报错
    3、成功
History     :
"""

import os
import unittest

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class OpreatorTest(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.common = Common()
        self.sh_primary = CommonSH('PrimaryDbBmode')
        self.user_node = Node('PrimaryDbBmode')
        self.constant = Constant()
        self.db_user = 'pt_user'

    def test_dolphin(self):
        text = '----step1:创建普通用户;expect:成功----'
        self.log.info(text)
        sql_cmd = f"drop user if exists {self.db_user};"\
                  f'create user {self.db_user} password'\
                  f"'{macro.COMMON_PASSWD}';"
        self.log.info(sql_cmd)
        sql_res = self.sh_primary.execut_db_sql(sql_cmd)
        self.log.info(sql_res)
        self.assertIn('CREATE ROLE', sql_res, '执行失败' + text)

        text = '----step2:切换用户,查看进程;expect:失败，合理报错----'
        self.log.info(text)
        sql_cmd1 = f'show processlist;'
        connect = f'-U {self.db_user} -W {macro.COMMON_PASSWD}'
        self.log.info(sql_cmd1)
        sql_res1 = self.sh_primary.execut_db_sql(sql_cmd1, sql_type=connect)
        self.log.info(sql_res1)
        self.assertIn("user", sql_res1,'执行失败' + text)


    def tearDown(self):
        text = '--step3:清理环境;expect:成功--'
        self.log.info(text)
        sql_cmd = f"drop user if exists {self.db_user};"
        sql_res = self.sh_primary.execut_db_sql(sql_cmd)
        self.assertNotIn("ERROR", sql_res, '执行失败' + text)
        self.log.info(f'-----{os.path.basename(__file__)} end-----')

